﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.UI.common;
using rock.common;

namespace rock.UI.custom
{
    public partial class FormSelectCustom : Form
    {
        private int CURRENT_PAGE = 1;
        DalRENT_CUSTOM dal = new DalRENT_CUSTOM();

        public FormSelectCustom()
        {
            InitializeComponent();
           // this.AcceptButton = this.button1;
            //this.CancelButton = this.button2;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            
            this.userControlCommonListHeader1.searchClick = searchClick;
            this.userControlCommonListPage1.pageClick = refreshData;
            this.Icon = global::rock.Properties.Resources.house;

            ViewUtils.setDataGridViewStlye(this.dataGridView1);
        }

        private void FormSelectCustom_Load(object sender, EventArgs e)
        {
          
            refreshData(1);
        }
        private void refreshData(int goPage)
        {
            CURRENT_PAGE = goPage;
            String search = this.userControlCommonListHeader1.textBox1.Text;

            PageDataSet ds = dal.GetListByPage("NAME LIKE '%" + search + "%'", " NAME ASC ", CURRENT_PAGE, Manager.getInstance().pageSize);
            this.dataGridView1.DataSource = ds.DataSet.Tables[0];
            this.userControlCommonListPage1.Inits(ds.AllRecord, this.CURRENT_PAGE);
           
        }
        private void searchClick()
        {
            refreshData(CURRENT_PAGE);
        }

  
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            String seqid = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["SEQID"].Value.ToString();

            selectedOk(Convert.ToInt32(seqid), 1);
            this.Close();

        }
        // 1:CUSTOM 2:ROOM
        public delegate void SelectedOk(int seqid, int type);
        public SelectedOk selectedOk;

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }
    }
}
